<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="../css/monokai-sublime.css">
    <link rel="stylesheet" href="../css/note.css">

    <script src="../js/highlight.pack.js"></script>
    <script src="../js/fixHighLight.js"></script>

    <script>

        hljs.initHighlightingOnLoad();

    </script>

    <title>mac book 编译 sqlcipher</title>
</head>
<body onload="replaceCode2ulli()">
<div class="detailTitle">mac book 编译 sqlcipher</div>
<div class="detailContent">

    <h3>背景介绍</h3>
    <p>全新macbook,啥环境也没有,需要编译安装sqlcipher</p>
    <h3>步骤</h3>
    <h3>1.先下载安装xcode,并安装命令行工具,准备gcc环境</h3>
<pre><code class="Bash">
xcode-select --install
</code></pre>

    <h3>2.安装brew</h3>

    <pre><code class="Bash">
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
</code></pre>


    <h3>3.安装openssl和tcl-tk</h3>
<pre><code class="Bash">
brew install openssl
brew install tcl-tk
</code></pre>

    <h3>4.下载sqlcipher源码</h3>
<pre><code class="Bash">
git clone https://github.com/sqlcipher/sqlcipher.git
</code></pre>

    <h3>5.配置你的.bash_profile</h3>
    <p>你可以不这么干,但我这么干顺利的编译成功了,你也可以这么干,完事注释掉即可!</p>
<pre><code class="Bash">
# for build sqlcipher 
export SQLITE_HAS_CODEC
export SQLITE_TEMP_STORE=2
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include -I/usr/local/opt/tcl-tk/include"
export PATH="/usr/local/opt/openssl/bin:$PATH"
export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
</code></pre>

    <h3>6.生效你的配置</h3>
    <pre><code class="Bash">
source ~/.bash_profile
</code></pre>

    <h3>7.开始编译</h3>
    <pre><code class="Bash">
./configure --enable-tempstore=yes CFLAGS=-DSQLITE_HAS_CODEC
make
make install
</code></pre>
    <h3>8.测试</h3>
    <pre><code class="Bash">
sqlcipher --version
</code></pre>
    <p>输出以下信息则表示成功.</p>
        <pre><code class="Bash">
3.20.1 2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34
</code></pre>



    <h3>加密你的数据库</h3>
    <p>假设你的数据库文件名叫a.db</p>
    <pre><code class="Bash">
sqlcipher a.db 
ATTACH DATABASE 'a_encrypted.db' AS a_en KEY ‘此处输入密码’;
SELECT sqlcipher_export('a_en');
DETACH DATABASE a_en;
.exit
    </code></pre>
    <p>ok了,生成的a_encrypted.db就是你的数据库文件,成功之后把你的.bash_profile里的配置前加#号注释掉吧</p>
    <p>祝你成功,并扫码下面,谢谢。</p>
</div>
<div class="note_footer">
    <p><font color=red>&hearts;</font></p>
    <img src="../images/qr.png"></img></div>
</body>
</html>